import { parseTime } from '@/utils/index'
import { dataSystemAddMap } from '@/config/dict.js'
export const queryFormItem = [
  {
    type: 'input',
    key: 'keyword',
    otherAttrs: {
      placeholder: '系统名称'
    }
  },
  {
    type: 'select',
    key: 'status',
    otherAttrs: {
      placeholder: '状态'
    },
    options: dataSystemAddMap
  }
]
// 状态: 1=有效 2=停用
const formatStatus = scope => {
  const result = {
    value: '',
    color: ''
  }
  switch (scope.row.status) {
    case 1:
      result.value = '启用'
      break
    case 2:
      result.value = '停用'
      result.color = '#a8a8a8'
      break
    default:
      break
  }
  return result
}
export const tableColumn = (page, size, handleUpdateStatus) => {
  return [
    {
      key: 'name',
      label: '名称',
      minWidth: 50
    },
    {
      key: 'remark',
      label: '备注',
      minWidth: 80
    },
    {
      key: 'createTime',
      label: '创建时间',
      minWidth: 80,
      render: (_, rocord) => parseTime(rocord.row.createTime)
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 50,
      render: (h, scope) => (
        <span style={'color:' + formatStatus(scope).color}>
          {formatStatus(scope).value}
        </span>
      )
    }
  ]
}

export const updateFormItem = handleAutomaticGenerate => {
  return [
    {
      type: 'input',
      key: 'name',
      label: '系统名称',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        }
      }
    },
    {
      type: 'input',
      key: 'appId',
      label: 'app_id',
      required: true,
      col: 12,
      slotAttrs: {
        style: {
          width: '248px'
        }
      }
    },
    {
      type: 'input',
      key: 'appSecret',
      label: 'app_secret',
      col: 24,
      required: true,
      slotAttrs: {
        style: {
          width: '97.5%'
        },
        slots: [
          {
            labelName: 'button',
            name: 'append',
            value: '生成',
            listen: {
              click: handleAutomaticGenerate
            }
          }
        ]
      }
    },
    {
      type: 'input',
      key: 'serverUrl',
      label: '服务器地址',
      col: 24,
      required: true,
      slotAttrs: {
        style: {
          width: '97.5%'
        }
      }
    },
    {
      type: 'input',
      key: 'testApiUrl',
      label: '测试接口',
      col: 12,
      slotAttrs: {
        style: {
          width: '95%'
        }
      }
    },
    {
      type: 'textarea',
      key: 'remark',
      label: '备注',
      col: 24,
      slotAttrs: {
        style: {
          width: '97.5%'
        }
      }
    }
  ]
}
